/* model */
import { 
  ConnectorBizTypeEnum, 
  ConnectorCreateDataSessionKeyInfix, 
  ConnectorCreateDataSessionKeyPrefix 
} from '@src/modules/connector/model'

/** 
 * @description 根据连接器业务类型生成连接器新建数据缓存键
*/
function genConnectorCreateDataSessionKeyByBizType(bizType: ConnectorBizTypeEnum, url: string) {

  // 附加组件不想一个个处理写key 所以写了一个枚举给所有的用
  if(bizType.includes('ADDITIONAL')) {
    bizType = ConnectorBizTypeEnum.Addons
  }

  return (
    ConnectorCreateDataSessionKeyPrefix + bizType + ConnectorCreateDataSessionKeyInfix + url
  )
}

/** 
 * @description 根据连接器业务类型获取连接器新建数据缓存键
*/
function getConnectorCreateDataSessionKeyByBizType(bizType: ConnectorBizTypeEnum) {
  
  const locationUrl = location.href.replace(location.origin, '')
  
  return (
    ConnectorCreateDataSessionKeyPrefix + bizType + ConnectorCreateDataSessionKeyInfix + locationUrl
  )
  
}

export {
  genConnectorCreateDataSessionKeyByBizType,
  getConnectorCreateDataSessionKeyByBizType
}
